const { Controller } = require('egg')

const updateRule = {
	name: {
		type: 'string',
		required: false,
	},
	avatar: {
		type: 'string',
		required: false,
	},
	mobile: {
		type: 'string',
		required: false,
	},
	proviceId: {
		type: 'string',
		required: false,
		description: '省id',
		example: '1',
	},
	cityId: {
		type: 'string',
		required: false,
	},
	areaId: {
		type: 'string',
		required: false,
	},
}
/**
 * @controller userInfo 用户信息
 */
class UserInfoController extends Controller {
	/**
	 * @summary 更新用户详情
	 * @description 更新用户详情
	 * @router put /admin/userInfo/{id}
	 * @request path string *id 标识
	 * @request body updateUserInfoRequest
	 */
	async update() {
		const ctx = this.ctx
		try {
			ctx.validate(updateRule, ctx.request.body)
            const { id } = ctx.params
			const status = await ctx.service.userInfo.update(
				id,
				ctx.request.body
			)
			if (status === 'success') {
				ctx.helper.success('更新成功')
			} else {
				ctx.helper.error(status)
			}
		} catch (e) {
			ctx.helper.error(e)
		}
	}
	/**
	 * @summary 用户详情
	 * @description 查看用户详情
	 * @router get /admin/userInfo/{id}
	 * @request path string *id 标识
	 */
	async show() {
		const ctx = this.ctx
		try {
			const { id } = ctx.params
			const data = await ctx.service.userInfo.show(id)
			if (data.status === 'success') {
				ctx.helper.success(data.body)
			} else {
				ctx.helper.error(data.status)
			}
		} catch (e) {
			ctx.helper.error(e)
		}
	}
}
module.exports = UserInfoController
